﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AgileDashboard.Entities;

namespace AgileDashboard.Data
{
    public class LocalDataLoader
    {

        public List<WorkItem> GetWorkItemsfromLocalStore(string userName)
        {
            using (var db = new PlanningPokerContext())
            {
                foreach (WorkItem wi in db.WorkItems)
                {
                    //wi.CanVote 
                    var voteCount = (from v in wi.VoteDetails
                                     select v).Count();

                    wi.VoteCount = voteCount;


                    var userVotes = (from v in wi.VoteDetails
                                     where v.UserName == userName
                                     select v).Count();

                    if (userVotes == 0)
                        wi.CanVote = true;


                }

                return db.WorkItems.ToList();
            }

        }


        public List<VoteDetail> GetVoteDetailsfromLocalStore(int workItemId)
        {
            using (var db = new PlanningPokerContext())
            {

                var workItem = (from w in db.WorkItems
                                where w.Id == workItemId
                                select w).FirstOrDefault();

                return workItem.VoteDetails.ToList();


            }

        }

    }

}
